package com.ias.agdis_r.view.control;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ias.agdis_r.bean.other.TempLabelBean;
import com.ias.agdis_r.util.S;
import com.ias.agdis_r.view.base.BaseGroupView;

/**
 * Group2TypeView 显示内容格式为: XXX：XXX XXX：XXX XXX：XXX XXX：XXX XXX：XXX XXX：XXX
 * XXX：XXX XXX：XXX
 * 
 * @param context
 * @author zhangsc
 */
public class Group2TypeView extends BaseGroupView {

	public Group2TypeView(Context context, ProgressBar progress) {
		super(context, progress);
		// TODO Auto-generated constructor stub
	}

	private LinearLayout child1Layout;
	private LinearLayout.LayoutParams child1lp;

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		// 设置自身布局为垂直布局
		this.setOrientation(LinearLayout.VERTICAL);
		child1lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		child1lp.topMargin = 4;
	}

	/**
	 * 根据TAG，将VIEW增加到Layout中
	 * 
	 * @param tag
	 */
	@Override
	public boolean addViewByTag(String infoTag, TempLabelBean labelBean) {
		try {
			this.viewNum++;

			child1Layout = new LinearLayout(getContext());
			child1Layout.setLayoutParams(child1lp);
			child1Layout.setOrientation(LinearLayout.HORIZONTAL);

			TextView labelView = new TextView(getContext());
			labelView.setText(labelBean.getContent() + ":");
			labelView.setTextSize(20);
			labelView.setPadding(12, 4, 12, 2);
			labelView.setTextColor(Color.BLACK);
			child1Layout.addView(labelView);
			TextView infoView = new TextView(getContext());
			infoView.setTag(infoTag);
			infoView.setTextSize(20);
			infoView.setPadding(0, 4, 12, 2);
			child1Layout.addView(infoView);
			// 判断此标签是否有超链接
			if (S.isNotEmpty(labelBean.getUrl())) {
				infoView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
				infoView.setTextColor(Color.BLUE);
				setOnClickListener(infoView, labelBean.getUrl());
			}
			addView(child1Layout);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public int getViewNum() {
		// TODO Auto-generated method stub
		return this.viewNum;
	}
}
